<template>
  <div class="list">
    <h2>猜你喜欢</h2>
    <div class="box1">
        <span :class="{active:arr4==i}"  v-for="(v,i) in arr" :key="i" @click="fun(i)">{{v}}</span>
    </div>
    <div class="box2">
        <span v-for="(v,i) in arr1" :key="i">{{v}}</span>
    </div>
     <div class="goods" v-for="(v,i) in arr3" :key="i">
        <img :src="v.picUrl" alt="">
        <div class="info">
            <h3>{{v.name}}</h3>
            <div class="content">
                <div class="num">
                  <span>4.9</span>
                  <p>{{v.monthSalesTip}}</p>
                </div>
                <p>{{v.minPriceTip}}，{{v.shippingFeeTip}} <del>￥6</del> <span>{{v.deliveryTimeTip}}</span></p>
                <div class="talk">
                    <span>"扬州炒饭棒棒哒"</span>
                    <span>"高新区畅销第2名"</span>
                </div>
                <div class="youhui">
                    <span v-for="(v,index) in arr3[i].discounts2" :key="index">{{v.info}}</span>
                </div>
            </div>
        </div>
    </div>
  </div>
</template>

<script>


import {shop_list} from "../utils/apis.js"
export default {
    data(){
        return{
            arr:["综合排序","距离最近","销量最高","筛选"],
            arr1:["年货节热卖","津贴联盟","满减优惠","品质联盟"],
            arr3:[],
            arr4:0,
           
        }
    },
     mounted(){ //这个方法会在组件挂载完成时 自动执行, 而且只执行一次
    //发送网络请求, 请求店铺列表
    shop_list().then((res)=>{
      this.arr3 = res.data.list;//保存从服务器返回的店铺列表数据, 这行代码修改了data中的响应式数据,会导致当前组件更新,组件会重新渲染
       
    })
    
  },
    methods:{
        fun(i){
            if(i==1){
                this.arr3.sort((a,b)=>{
                    return a.deliveryTimeTip.slice(0,2)-b.deliveryTimeTip.slice(0,2)
                   
                })
            }else if(i==2){
                this.arr3.sort((a,b)=>{
                    return b.monthSalesTip.slice(2)-a.monthSalesTip.slice(2)
                })
            }
            this.arr4=i
        },  
    },
   
}
</script>

<style lang="scss" scoped>
.list{
    box-sizing: border-box;
    padding: 0 15px;
    h2{
        font-size: 20px;
    }
    .box1{
        display: flex;
        justify-content: space-between;
        padding: 10px 0;
        .active{
            font-weight: bold;
        }
    }
    .box2{
        display: flex;
        justify-content: space-between;
        >span{
            padding: 5px 10px;
            background-color: rgb(205, 191, 191);
            font-size: 14px;
            border-radius: 5px;
        }
    }
}
.goods{
    display: flex;
    margin: 10px 0;
    >img{
        margin-top :15px ;
        width: 120px;
        height: 120px;
    }
    .info{
        margin-left: 8px;
        h3{
            margin: 0;
        }
        .content {
            .num{
            display: flex;
            align-items: center;
            >span{
                color: #ff6300;
            }
            >p{
            margin: 5px 0;
            font-size: 14px;
            }
           }
           >p{
            margin: 5px 0;
            font-size: 14px;
            margin-left: 5px;
            del{
                color: rgb(188, 182, 182);
            }
           }
        }
        .talk{
            display: flex;
            justify-content: space-between;
            >span{
                font-size: 12px;
                color: #fe7100;
                padding: 3px 4px;
                background-color: #ffeee0;
                margin-right: 4px;
            }
        }
        .youhui{
            margin-top: 6px;
            display: flex;
            >span{
                font-size: 12px;
                color: #f00;
                border:1px solid #ffc9c1;
                // padding: 2px 4px;
                margin-right: 3px;
            }
        }
   
    }
}
</style>